package com.czkt.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.czkt.shop.pojo.ProductSku;
import com.czkt.shop.mapper.ProductSkuMapper;
import com.czkt.shop.service.IProductSkuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2024-09-04
 */
@Service
public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, ProductSku> implements IProductSkuService {

    @Override
    public ProductSku list(String attr, Long spuId) {
        LambdaQueryWrapper<ProductSku> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(attr != null && attr != "",ProductSku::getProductSkuName,attr)
                .eq(spuId != null,ProductSku::getSpuId,spuId);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<ProductSku> list(Set<Long> skuId) {

        LambdaQueryWrapper<ProductSku> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.in(skuId != null,ProductSku::getProductSkuId,skuId);

        return baseMapper.selectList(queryWrapper);
    }
}
